package 并发编程12.aqs源码分析;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.Lock;

/**
 * @author idea
 * @data 2019/1/26
 */
public class MyLockDemo {


    public List<Integer> list = new ArrayList<>();
    public Lock lock = new MyLock();

    public void insert() {
        try {
            lock.lock();
            for (int i = 0; i < 100; i++) {
                list.add(i);
                Thread.sleep(10);
            }
            System.out.println(list.size());
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            lock.unlock();
        }
    }

    public static void main(String[] args) {
        final MyLockDemo t = new MyLockDemo();
        new Thread() {
            @Override
            public void run() {
                t.insert();
            }
        }.start();

        new Thread() {
            @Override
            public void run() {
                t.insert();
            }
        }.start();

    }

}
